﻿@using PagedList;
@model PagedList.IPagedList<ProjectThuCung.Models.SanPham>

@{
    ViewBag.Title = "Danh sách vật phẩm";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


<div style="margin:30px">
    <h2>Danh sách tất cả các vật phẩm</h2>

    @using (Html.BeginForm())
    {
        <p>
            Tìm vật phẩm: @Html.TextBox("searchString",  ViewBag.CurrentFilter as string)  
            <input type="submit" value="Tìm" />
        </p>
    }

    <p>
        @Html.ActionLink("Thêm vật phẩm", "Create")
    </p>
    <table>
        <tr>
            <th>
                Hình ảnh
            </th>
            <th>
                @Html.ActionLink("Tên thương mại", "Index", new { sortOrder=ViewBag.TenSanPhamSortParm, currentFilter=ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("Loại", "Index", new { sortOrder=ViewBag.LoaiSanPhamSortParm, currentFilter=ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("Xuất xứ", "Index", new { sortOrder=ViewBag.XuatXuSortParm, currentFilter=ViewBag.CurrentFilter })
            </th>
            <th>
                Mô tả khái quát
            </th>
            <th>
                @Html.ActionLink("Giá (k)", "Index", new { sortOrder=ViewBag.GiaSortParm, currentFilter=ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("Số lượng còn", "Index", new { sortOrder=ViewBag.SoLuongSortParm, currentFilter=ViewBag.CurrentFilter })
            </th>
            <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @if (item.HinhAnh != null)
                {
                    <img alt="@item.TenSanPham" src ="@item.HinhAnh" height = "100" width = "100" />
                }
                else
                {
                    <img alt="đang cập nhật" src="~/Images/NoneHinhAnh.png" height = "100" width = "100" />
                }
            </td>
            <td>
                @(item.TenSanPham)
            </td>
            <td>
                @(item.LoaiSanPham.TenLoaiSanPham)
            </td>
            <td>
                @(item.XuatXu.TenXuatXu)
            </td>
            <td>
                @Html.Raw(System.Web.HttpUtility.HtmlDecode(item.MoTa))
            </td>
            <td style ="text-align:center">
                @(item.Gia)
            </td>
            <td style ="text-align:center">
                @(item.SoLuong)
            </td>
            <td>
                @Html.ActionLink("Chỉnh sửa", "Edit", new { id=item.SanPhamID }) |
                @Html.ActionLink("Chi tiết", "Details", new { id=item.SanPhamID }) |
                @Html.ActionLink("Xóa", "Delete", new { id=item.SanPhamID })
            </td>
        </tr>
    }

    </table>
    <div>
        Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        of @Model.PageCount
     
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("<<", "Index", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
            @Html.Raw(" ");
            @Html.ActionLink("< Pre", "Index", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
        }
        else
        {
            @:<<
            @Html.Raw(" ");
            @:< Prev
        }
     
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("Next >", "Index", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
            @Html.Raw(" ");
            @Html.ActionLink(">>", "Index", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter  })
        }
        else
        {
            @:Next >
            @Html.Raw(" ")
            @:>>
        }
    </div>
</div>